"use strict";
/* Controllers */
app.controller("approverConfigEditController", ['$scope', '$location', '$rootScope', '$q', '$routeParams', 'approverConfigEditService', function ($scope, $location, $rootScope, $q, $routeParams, approverConfigEditService) {

    var vm = $scope.vm = {};
    vm.p = {};
    var routeId = $routeParams.id;

    //e_time\s*[\)]?\s*[>|>=|<|<=|=]{1,2}\s*['|"]{1}%s['|"]{1}
    var errorFn = function (result) {
        alert(result);
    };

    $scope.getProductInfo = function () {
        var vm = $scope.vm;
        var params = {
            id: routeId
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data
            } else {
                alert(res.msg);
            }
        };
        return approverConfigEditService.getProductInfo(params, procFn, errorFn);
    };

    $scope.productInfoSave = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success) {
                alert("保存成功！")
            } else {
                alert(response.msg);
            }
        };
        approverConfigEditService.save(params, procFn, errorFn);
    };

    if (typeof (routeId) != "undefined" && routeId != null) {
        $scope.getProductInfo()
    }
}]);


/* Services */
app.service('approverConfigEditService', ['ajaxService', function (ajaxService) {

    this.save = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/approver_config/save.do", successFunction, errorFunction);
    };

    this.getProductInfo = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/approver_config/detail.do", successFunction, errorFunction);
    };

}]);

